﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// 买卖股票的最佳时机
/// 贪心算法：考虑局部最优解
/// </summary>
namespace PrimaryAlgorithm.MaxProfit
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] nums = new int[] { 7, 1, 5, 3, 6, 4 };
            Console.WriteLine(MaxProfit(nums));
            Console.ReadKey();
        }
        public static int MaxProfit(int[] prices)
        {
            int max = 0;
            for (int i = 0; i < prices.Length-1; i++)
            {
                if (prices[1+i]> prices[i])
                {
                    max += (prices[1 + i] - prices[i]);
                }
            }
            return max;
        }
    }
}
